//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_RENDER_H
#define _UX_RENDER_H

#include "CRenderThread.h"
#include "../Threads/IThreadOperation.h"

namespace Engine
{
namespace CoreSystems
{

	//
	// Render
	//

	class _EXPORT_ CRender : public CEngBaseObject
	{
		friend class Engine::CoreSystems::CCore;
		friend class Engine::CoreSystems::CRenderThread;
		
	protected:
		struct TPerThreadRender
		{
			CRenderThread	*	pRender;
			IThread			*	pWindow;
			bool				bIsFree;
			///
			TPerThreadRender(): pRender(nullptr), pWindow(nullptr), bIsFree(true) {}
			TPerThreadRender(CRenderThread *ren, IThread *win, bool isfree = true):
				pRender(ren), pWindow(win), bIsFree(isfree) {}
		};

	protected:
		CTBOManager					_cTBOMan;
		CLDevice					_cDevice;
		CRenderProfiler				_cProfiler;
		CRenderTechniqueManager		_cRTMan;
		CPostProcessManager			_cPPMan;
		CGLObjectManager			_cObjMan;
		CUniformManager				_cUnMan;

		array< IWindow *>			_aRenders;
		usize						_uRenderThreads,
									_uLoadThreads;
		TReadWriteSync				_sLockRenders;

	protected:
		CRender();
		~CRender();

		bool Init(const TEngInitParams &sInit);
		bool Init2(const TEngInitParams &sInit);
		bool InitDefPrograms();
		void FreeDefPrograms();

		static void _s_InitRender(void *);

		// CEngBaseObject //
		virtual void Release();

	public:
		bool PushRenderOp(IOperation *pOp, bool bHighPriority);
		bool PushOpToRenders(IOperationC *pOp, bool bHighPriority);
		bool PushOpToAll(IOperationC *pOp, bool bHighPriority, bool bExceptMain);

		bool GetRenderThreads(thread_array_t &aThreads);
		bool GetLoadThreads(thread_array_t &aThreads);
		bool GetAllThreads(thread_array_t &aThreads);
	};

//-------------------------------------------------------------------

}	// CoreSystems
}	// Engine

#endif	// _UX_RENDER_H